package cn.com.bluemoon.daps.standard.api.factory;

import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.standard.api.RemoteStandardDataTypeService;
import cn.com.bluemoon.daps.standard.entity.DapStandardDataType;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Jarod.Kong
 * @date 2021/3/25 13:25
 */
@Component
@Slf4j
public class RemoteStandardDataTypeFactory implements FallbackFactory<RemoteStandardDataTypeService> {

    @Override
    public RemoteStandardDataTypeService create(Throwable throwable) {
        log.error("初始化数据标准字段类型定义接口");
        return new RemoteStandardDataTypeService() {
            @Override
            public ResultBean<List<DapStandardDataType>> getDataTypeByDbType(Integer dbType) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiStandard.PROD_SERVICE, "获取数据类型基础数据失败！！");
            }

            @Override
            public ResultBean<List<DapStandardDataType>> listDataTypes() {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiStandard.PROD_SERVICE, "获取数据类型基础数据失败！！");
            }
        };
    }
}
